const { View , Text } = require("@tarojs/components");
import './MineBooked.less'
import http from '../../../../utils/http'
import Taro,{useReady} from '@tarojs/taro'
import React, { useState} from 'react'
//我的预约页面 

const Con = () => {
    
    const [arr,setArr]=useState([])

    let look=(a,b)=>{  //列表页跳转相应页面
        if(arr[a].order_status==0){  //待体检
            Taro.navigateTo({
                url:'/pages/HXM/MineBookedDetails/MineBookedDetails?index='+a+'&&id='+b,
            })
        }else if(arr[a].order_status==1){  //待支付
            Taro.navigateTo({
                url:'/pages/HXM/AwaitPayment/AwaitPayment?index='+a+'&&id='+b,
            })
        }else if(arr[a].order_status==2){  //已体检
            Taro.navigateTo({
                url:'/pages/HXM/AccomplishPhysical/AccomplishPhysical?index='+a+'&&id='+b,
            })
        }else{
            Taro.navigateTo({  //体检预约详情  已取消预约
                url:'/pages/HXM/CancelRefundDetails/CancelRefundDetails?index='+a+'&&id='+b,
            })
        }
    }

    useReady(() => {
        http({   //获取我的体检详细
            url:"/getminebooked",
            data:{
                user_tel:15184462493
            },
            header:{
                'content-type': 'application/json' 
            },
        }).then((res)=>{
            setArr(res)     
        })
      })

      const fromData=(a)=> {   //后台传前台时间格式转换
        let time = new Date(a)
        let month = time.getMonth() + 1 
        let date = time.getDate()
        let hours = time.getHours()
        let minutes = time.getMinutes()
        // let second = time.getSeconds() // 获取秒数
        // 小于10前加一个0
        if(month < 10) {
          month = '0' + month
        }
        if(date < 10) {
          date = '0' + date
        }
        return time.getFullYear() + '-' + month + '-' + date 
    }
 
    return(
        <View className="body">
            {
            arr.map(
                (v,i)=>(
                <View 
                onClick={look.bind(this,i,v.order_orderId)} className="view1"
                >
                    <View className="view1-1">
                        <View>{v.user_name} {v.user_tel}</View>
                        <Text style={{color:(v.order_status==0?'green':v.order_status==1?'orange':'grey')}}>
                        {v.order_status==0?'待体检':v.order_status==1?'待支付':v.order_status==2?'已体检':'已取消'}
                        </Text>
                    </View>
                    <View className="view1-2">
                        <View>
                            体检机构: <Text> {v.org_Name}</Text>
                        </View>
                        <View>
                            体检时间: <Text> {fromData(v.order_date)}</Text>
                        </View>
                        <View>
                            体检单号: <Text> {v.order_orderId}</Text>
                        </View>
                    </View>
            </View>)
            )
            }
        </View>
    )
    
}

function MineBooked () {
    return(
        <View>
           <Con/>
	    </View>
    )
}
export default MineBooked